package online.shenjian.mq.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(name = "spring.rabbitmq.enable", matchIfMissing = true)
public class RpcConfig {

    @Bean
    public DirectExchange rpc() {
        return new DirectExchange("rpc");
    }

    private static class ServerConfig {

        @Bean
        public Queue rpcQueue() {
            return new Queue("rpc.requests");
        }

        @Bean
        public Binding binding(DirectExchange rpc,
                               Queue rpcQueue) {
            return BindingBuilder.bind(rpcQueue)
                    .to(rpc)
                    .with("rpc");
        }
    }
}
